//
//  LLEmoticonPageView.swift
//  xinlangweibo
//
//  Created by 任玉林 on 16/7/4.
//  Copyright © 2016年 任玉林. All rights reserved.
//

import UIKit

private let cellId = "cell"

class LLEmoticonPageView: UICollectionView {

    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //设置视图
    func setupUI(){
        
       dataSource = self
        
        //注册
        registerClass(LLEmoticonPageViewCell.self, forCellWithReuseIdentifier: cellId)
        
        //设置layout
        let layout = collectionViewLayout as!UICollectionViewFlowLayout
        
        layout.itemSize = CGSize(width: SCREENW, height: 216 - 37)
        
        layout.minimumInteritemSpacing = 0
        
        layout.minimumLineSpacing = 0
        
        layout.scrollDirection = .Horizontal
        
    }

}

extension LLEmoticonPageView: UICollectionViewDataSource{
    
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        
        return LLEmojiTool.sharedTool.allemoticons.count
    }
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
        return LLEmojiTool.sharedTool.allemoticons[section].count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(cellId, forIndexPath: indexPath) as! LLEmoticonPageViewCell
        
        cell.indexpath = indexPath
        
        cell.emoticons = LLEmojiTool.sharedTool.allemoticons[indexPath.section][indexPath.item]
        
        return cell
    }
    
}
